layui.config({
	base: '/static/plugin/build/js/'
}).use(['tab', 'element', 'navbar'], function() {
	var element = layui.element;
	var $ = layui.$;
	var tab = layui.tab;
	var navbar = layui.navbar;
	var realname = localStorage.getItem("realname");
	$("#main-role").html("欢迎您，"+realname);
	tab.set({
		renderType: 'iframe',
		elem: '#container',
		mainUrl: '/pages/home/index.html',
		onSwitch: function(data) { //选项卡切换时触发
			id = data.layId;
		},
		closeBefore: function(data) { //关闭选项卡之前触发
			return true; //返回true则关闭
		}
	}).render();
	navbar.bind(function(data) {
		tab.tabAdd(data);
	});
	getmenu();

	function getmenu() {
		$.get(
			"/mock/menu.json",
			function(data) {
				var menuList = data.menu;
				navbar.set({
					data: menuList
				}).render(function(data) {
					tab.tabAdd(data);
				});
			},
			"json"
		);
	}
	$(".layui-side-scroll").on('click', 'a', function() {
		var dds = $(".layui-tab-title li").length;
		if(dds >= 7) {
			layer.open({
				content: '打开的选项卡过多，只保留当前选项卡',
				yes: function(index, layero) {
					layer.close(index);
					$(".kit-tab ul.layui-tab-title").children("li[lay-id]").each(function() {
						var ids = $(this).attr("lay-id");
						if(ids != id && ids !== undefined && ids != -1) {
							element.tabDelete('kitTab', ids);
						}
					});
					//如果设定了yes回调，需进行手工关闭
				}
			});
		}
	});
	//全屏
	var flag = true;
	$("#fullscreen").on("click", function() {
		if(flag) {
			flag = false;
			fullScreen();
		} else {
			flag = true;
			exitFullScreen();
		}
	});

	function fullScreen() {
		elem = document.documentElement;
		if(elem.webkitRequestFullScreen) {
			elem.webkitRequestFullScreen();
		} else if(elem.mozRequestFullScreen) {
			elem.mozRequestFullScreen();
		} else if(elem.requestFullScreen) {
			elem.requestFullscreen();
		} else {
			alert("请按键盘F11实现功能");
		}
	}

	function exitFullScreen() {
		var elem = document;
		if(elem.webkitCancelFullScreen) {
			elem.webkitCancelFullScreen();
		} else if(elem.mozCancelFullScreen) {
			elem.mozCancelFullScreen();
		} else if(elem.cancelFullScreen) {
			elem.cancelFullScreen();
		} else if(elem.exitFullscreen) {
			elem.exitFullscreen();
		} else {
			alert("请按键盘F11实现功能");
		}
	}

});